<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>质数判断</title>
</head>

<body>

    <script>
        function iszhishu(number) {

            //质素：因子只有1和它本身；
            if (number > 1) {
                //用count变量来记录 有多少个数 能被number除尽，余数为0。
                var count = 0;
                for (var i = 2; i <number; i++) {
                    if (number % i == 0) {
                        count++;
                        if (count > 2) {
                            return false;
                        }
                    }
                }
                //如果for循环执行完毕，发现conunt ==2；那么代表number只能除尽1和它本身
                // 所以，number为质数
                if (count == 2) {
                    return true;
                }
                  return false;
                }
                  else{
                    return false;
            }
            var result = iszhishu(97);
            console.log(result);
    </script>
</body>
</html>